﻿Imports System
Imports System.Resources
Imports System.Reflection
Imports System.Threading
Imports System.Globalization

Public Class RoundButton

    Event OnFinger()


    Private _MState As MyState
    Private Property MState() As MyState
        Get
            Return _MState
        End Get
        Set(ByVal value As MyState)
            _MState = value
        End Set
    End Property

    Private _ResName As String
    Public Property ResName() As String
        Get
            Return _ResName
        End Get
        Set(ByVal value As String)
            _ResName = value
        End Set
    End Property

    Private Sub picButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles picButton.Click
        RaiseEvent OnFinger()
    End Sub

    Private Sub picButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picButton.MouseDown
        Me.MState = MyState.Click
        picButton.Refresh()
    End Sub

    Private Sub picButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles picButton.MouseUp
        Me.MState = MyState.Normal
        picButton.Refresh()
    End Sub

    Private Sub picButton_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles picButton.Paint
        Dim X As Integer = 0

        If Me.Enabled Then
            Select Case MState
                Case MyState.Normal
                    X = 0
                Case MyState.Click
                    X = -Me.Width
                Case Else
                    X = -Me.Width * 2
            End Select
        Else
            X = -Me.Width * 2
        End If
        e.Graphics.DrawImage(Me.GetImage, X, 0)
    End Sub

    Private Function GetImage() As System.Drawing.Bitmap
        Dim ResourceManager As New System.Resources.ResourceManager("YAGPS.Resources", [Assembly].GetExecutingAssembly())
        Dim obj As Object = ResourceManager.GetObject(Me.ResName)
        Return CType(obj, System.Drawing.Bitmap)
    End Function

    Private Enum MyState
        Normal
        Click
    End Enum

    Private Sub RoundButton_EnabledChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.EnabledChanged
        picButton.Refresh()
    End Sub
End Class
